'use strict';

define([
	'jquery',
	'underscore',
	'backbone',
	'bootstrap',
	'backgrid',
	'backgrid-paginator',
	'backgrid-mypaginator',
	'backgrid-button-cell',
	'text!modules/supplier/supplier.html',
	'supplierModel',
	'supplierCollection',
	'supplierPageableCollection',
	'../modules/supplier/supplierModelDialogView'
],function(
	$,
	_,
	Backbone,
	Bootstrap,
	Backgrid,
	BackgridPaginator,
	BackgridMyPaginator,
	BackgridButtonCell,
	supplierV,
	SupplierM,
	SupplierC,
	SupplierPageableC,
	SupplierModelDialogV
){
	var supplierView=Backbone.View.extend({
		
		viewName:'supplierView',
		
		supplierPageableCollection: new SupplierPageableC(),
		
		el:'.main-content',
		
		events:{
			'click #btnOpenDialog':'showModelSupplier'
		},
		
		initialize:function(){
			$(this.el).html(supplierV);
		},
		
		render:function(){
			//显示供应商列表
			this.showSupplierList();
			
			//添加模态框子视图
			var view =new SupplierModelDialogV();
			this.setSubView(view);
		},
		
		/*供应商模态框显示*/
		showModelSupplier:function(){
			var view=this.getSubView('supplierModelDialogView');
			view.show();
		},
		
		/*显示供应商列表*/
		showSupplierList:function(){
			
			var supplierPageableCollection=this.supplierPageableCollection;
			
			var gridSupplier=new Backgrid.Grid({				
				className: "backgrid table table-striped table-bordered table-hover",
				columns: [
							{
					           name: "Code",
					           cell: "string",
					           label:'供应商编号',
					           sortable:false,
					           editable: false
					         }, 
							{
					          name: "Name",
					          cell: "string",
					          label:'供应商名称',
					          sortable:false,
					          editable: false
					        }, 
					         {
					           name: "UpdateTime",
					           cell: "date",
					           label:'最近上货时间',
					           sortable:true,
					           editable: false
					         }, 
					         {
					           name: "Operation",
					           cell: "button",
					           label:'操作',
					           sortable:false,
					           editable: false
					         }
					    ],
					
				collection: supplierPageableCollection
			});
			
			var paginatorSupplier = new Backgrid.Extension.MyPaginator({
				el:'#paginatorSupplier',				
		        collection: supplierPageableCollection
		       
		    });
		    
		    $("#gridSupplier").html(gridSupplier.render().$el);
      		
      		this.supplierPageableCollection.refresh();
		}
		
	});
	
	return supplierView;
});
